package com.tool.enums;

import org.apache.commons.lang3.StringUtils;

public enum TypeEnum {

	/** VARCHAR */
	VARCHAR("VARCHAR", "String"),
	/** CHAR */
	CHAR("CHAR", "String"),
	/** LONGVARCHAR */
	LONGVARCHAR("LONGVARCHAR", "String"),
	/** NUMERIC */
	NUMERIC("NUMERIC", "java.math.BigDecimal"),
	/** BIT */
	BIT("BIT", "boolean"),
	/** TINYINT */
	TINYINT("TINYINT", "byte"),
	/** SMALLINT */
	SMALLINT("SMALLINT", "short"),
	/** INTEGER */
	INTEGER("INTEGER", "int"),
	/** BIGINT */
	BIGINT("BIGINT", "long"),
	/** REAL */
	REAL("REAL", "float"),
	/** FLOAT */
	FLOAT("FLOAT", "double"),
	/** DOUBLE */
	DOUBLE("DOUBLE", "double"),
	/** BINARY */
	BINARY("BINARY", "byte[]"),
	/** VARBINARY */
	VARBINARY("VARBINARY", "byte[]"),
	/** LONGVARBINARY */
	LONGVARBINARY("LONGVARBINARY", "byte[]"),
	/** DATE */
	DATE("DATE", "java.sql.Date"),
	/** TIME */
	TIME("TIME", "java.sql.Time"),
	/** TIMESTAMP */
	TIMESTAMP("TIMESTAMP", "java.util.Date"),;

	private String jdbcType;

	private String javaType;

	TypeEnum(String jdbcType, String javaType) {
		this.jdbcType = jdbcType;
		this.javaType = javaType;
	}

	public String getJdbcType() {
		return jdbcType;
	}

	public String getJavaType() {
		return javaType;
	}

	public static TypeEnum findByJdbcType(String jdbcType) {
		if (StringUtils.isBlank(jdbcType)) {
			return null;
		}
		for (TypeEnum typeEnum : TypeEnum.values()) {
			if (jdbcType.trim().equalsIgnoreCase(typeEnum.getJdbcType())) {
				return typeEnum;
			}
		}

		return null;
	}

}
